﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Interfaces;
using dto;

namespace GABA
{
    public partial class MainWindow : Form, IView   
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private ChromosomType encoding=ChromosomType.real;
        private FitnessFunktion fitnessFct = FitnessFunktion.Griewank;
        private Crossover cross = Crossover.OnePoint;
        private Selection selection = Selection.Deterministic;
        private bool generationdependentMR = false;
        private void MainWindow_Load(object sender, EventArgs e)
        {

        }

        private void startAlgo_Click(object sender, EventArgs e)
        {
            int populationSize=Convert.ToInt32(populationSizeMaskedTextBox.Text);
            int maxGenerations=Convert.ToInt32(generationSizeMaskedTextBox.Text);
            double mutationrate = Convert.ToDouble(mutationRate.Text);
            double crossoverrate =Convert.ToDouble(CrossoverRate.Text);
            int chromosomesize = Convert.ToInt32(chromosomeSizeMaskedTextBox.Text);


            controller.start(populationSize, maxGenerations, selection, cross, fitnessFct, encoding, mutationrate, generationdependentMR,crossoverrate,chromosomesize );
        }

        void IView.initialize(IController controller)
        {
            this.controller = controller;
        }


        void IView.sendMessage(string p)
        {
            outputView.Items.Add(p);
        }

        private void binaryEncodingRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (binaryEncodingRadioButton.Checked)
            { encoding = ChromosomType.binary; }
        }

        private void realEncodingRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (realEncodingRadioButton.Checked)
            {
                encoding = ChromosomType.real; 
            }
        }

        private void griewankFctRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (griewankFctRadioButton.Checked) 
            {
                fitnessFct = FitnessFunktion.Griewank;
            }
        }

        private void ackleyFctRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (ackleyFctRadioButton.Checked)
            {
                fitnessFct = FitnessFunktion.Ackley;
            }
        }

        private void cFctRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (cFctRadioButton.Checked)
            {
                fitnessFct = FitnessFunktion.CFunction;
            }
        }

        private void nullFctRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (nullFctRadioButton.Checked)
            {
                fitnessFct = FitnessFunktion.NullValue;
            }
        }

        private void onePointRecombRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (onePointRecombRadioButton.Checked)
            {
               cross = Crossover.OnePoint;
            }
        }

        private void twoPointRecombRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (twoPointRecombRadioButton.Checked)
            {
                cross = Crossover.TwoPoint;
            }
        }

        private void templateRecombRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (templateRecombRadioButton.Checked)
            {
                cross = Crossover.Template;
            }
        }

        private void rouletteSelection_CheckedChanged(object sender, EventArgs e)
        {
            if (rouletteSelection.Checked)
            {
                selection = Selection.RouletteWheel;
            }
        }

        private void tournamentSelection_CheckedChanged(object sender, EventArgs e)
        {
            if (tournamentSelection.Checked)
            {
                selection = Selection.Tournament;
            }
        }

        private void eliteSelection_CheckedChanged(object sender, EventArgs e)
        {
            if (eliteSelection.Checked)
            {
                selection = Selection.Deterministic;
            }
        }

        private void rankSelection_CheckedChanged(object sender, EventArgs e)
        {
            if (rankSelection.Checked)
            {
                selection = Selection.Rank;
            }
        }

        private void generationdependentMutationrate_CheckedChanged(object sender, EventArgs e)
        {
            if (generationdependentMutationrate.Checked)
            {
                generationdependentMR = true;
            }
            else { generationdependentMR = false; }
        }

    }
}
